import {Card} from 'antd';
import React from 'react';
import {PageContainer} from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table';
import type {TableListItem} from './data.d';
import {queryStatisticsList} from './service';
import {formatDate, NumberDiv} from "@/utils/function";
import {queryUse} from "@/utils/service";
import {number} from "echarts";

const TableList: React.FC = () => {
  const columns: any[] = [
    {
      title: "交易对",
      dataIndex: 'symbol',
      fixed:"right",
      width: 90,
      tip: '交易对是唯一的 key',
    },
    {
      title: "开始时间",
      dataIndex: 'startTime',
      width: 120,
      renderText: (val: string) => formatDate(val, false)
    },
    {
      title: "强平价格",
      width: 120,
      dataIndex: 'liquidationPrice',
      renderText: (val: string | number) => NumberDiv(val,1,4)
    },
    {
      title: "期货杠杆",
      width: 120,
      dataIndex: 'lever',
    },
    {
      title: "当前现货价格",
      width: 100,
      dataIndex: 'lastGoodsPrice',
    },
    {
      title: "下一次资金费率",
      width: 120,
      dataIndex: 'lastFundingRate',
    },
    {
      title: "当前合约价格",
      width: 120,
      dataIndex: 'lastContractPrice',
    },
    {
      title: "现货买入成本价格",
      width: 120,
      dataIndex: 'goodsPrice',
    },
    {
      title: "现货数量",
      width: 100,
      dataIndex: ' goodsNum',
    },
    {
      title: "浮动盈亏",
      width: 100,
      dataIndex: 'floatingProfit',
    },
    {
      title: "期货买入成本价格",
      width: 100,
      dataIndex: 'contractPrice',
    },
    {
      title: "期货数量",
      width: 100,
      dataIndex: 'contractNum',
    },
    {
      title: "佣金/手续费",
      width: 100,
      dataIndex: 'commission',
    },
    {
      title: "套利年后收益率",
      width: 100,
      dataIndex: 'arbitrageProfitYearRate',
    },
    {
      title: "套利收益率",
      width: 100,
      dataIndex: 'arbitrageProfitRate',
    },
    {
      title: "套利利润",
      width: 100,
      dataIndex: 'arbitrageProfit',
    },
    {
      title: "总盈亏",
      width: 100,
      dataIndex: 'allProfit',
    },
  ];

  return (
    <PageContainer>
      <Card>
        <ProTable<TableListItem>
          headerTitle={"现货下单记录列表"}
          rowKey="key"
          bordered
          pagination={false}
          scroll={{x: 2500, y: 300}}
          search={false}
          // @ts-ignore
          request={async (params = {}, sort, filter) => {
            //console.log(sort, filter);
            const msg = await queryStatisticsList();
            let data = queryUse(msg)
            if(data){
              return {
                data: data,
                // success 请返回 true，
                // 不然 table 会停止解析数据，即使有数据
                success: true,
                // 不传会使用 data 的长度，如果是分页一定要传
                total: number,
              };
            }else{
              return {
                data: data,
                success: false,
              };
            }
          }}
          columns={columns}
        />
      </Card>

    </PageContainer>
  );
};

export default TableList;
